<template>
	<view>
		<view class="nav2">
			<u-navbar title="券包" bgColor="transparent" :fixed="false" autoBack></u-navbar>
		</view>
		<view class="m30">
			<view class="flex-au">
				<view v-for="(item,index) in navList" :key="index" class="c999 f28"
					:class="{'active pore':navIndex == index}" @click="navClick(index)">
					{{item.name}}
				</view>
			</view>
			<u-gap height="20"></u-gap>
			<view class="" v-if="listData.length">
				<view class="yhq-item pore p30 mb20" v-for="(item,index) in listData" :key="index">
					<view class="pore">
						<view class="flex" v-if="item.coupon.conpType == 1">
							<view class="mr30">
								<view :class="item.useStauts > 0?'c999':'cyellow'">
									<text class="f24">￥</text>
									<text class="f40 bold">{{item.coupon.conpTextObject.deductionAmount}}</text>
								</view>
								<view class="f24" :class="item.useStauts > 0?'c999':'cyellow'">
									满{{item.coupon.conpTextObject.fullAmount}}可用</view>
							</view>
							<u-line length="100rpx" color="#eee" direction="col"></u-line>
							<view class="ml30 flex1" :class="item.useStauts  > 0?'c999':'c343'">
								<view class="bold f28 mb10">{{item.coupon.name}}</view>
								<view class="f24" v-if="item.coupon.lifespanType == 1">有效期：{{item.coupon.lifespanTextObject.startTime}} ~
									{{item.coupon.lifespanTextObject.endTime}}</view>
								<view class="f24" v-if="item.coupon.lifespanType == 2">有效期：{{item.coupon.lifespanTextObject.lifespan}}天</view>
							</view>
						</view>
						<view class="flex" v-if="item.coupon.conpType == 2">
							<view class="mr30">
								<view :class="item.useStauts > 0?'c999':'cyellow'">
									<text class="f40 bold">{{item.coupon.conpTextObject.discount}}折</text>
								</view>
								<view class="f24" :class="item.useStauts > 0?'c999':'cyellow'">
									最高减{{item.coupon.conpTextObject.maxReduction}}元</view>
							</view>
							<u-line length="100rpx" color="#eee" direction="col"></u-line>
							<view class="ml30 flex1" :class="item.useStauts  > 0?'c999':'c343'">
								<view class="bold f28 mb10">{{item.coupon.name}}</view>
								<view class="f24" v-if="item.coupon.lifespanType == 1">有效期：{{item.coupon.lifespanTextObject.startTime}} ~
									{{item.coupon.lifespanTextObject.endTime}}</view>
								<view class="f24" v-if="item.coupon.lifespanType == 2">有效期：{{item.coupon.lifespanTextObject.lifespan}}天</view>
							</view>
						</view>
						<view class="flex" v-if="item.coupon.conpType == 3">
							<view class="mr30">
								<view :class="item.useStauts > 0?'c999':'cyellow'">
									<text class="f32 bold">无门槛</text>
								</view>
								<view class="f24" :class="item.useStauts > 0?'c999':'cyellow'">
									满0可用</view>
							</view>
							<u-line length="100rpx" color="#eee" direction="col"></u-line>
							<view class="flex1 ml30" :class="item.useStauts  > 0?'c999':'c343'">
								<view class="bold f28 mb10">{{item.coupon.name}}</view>
								<view class="f24" v-if="item.coupon.lifespanType == 1">有效期：{{item.coupon.lifespanTextObject.startTime}} ~
									{{item.coupon.lifespanTextObject.endTime}}</view>
								<view class="f24" v-if="item.coupon.lifespanType == 2">有效期：{{item.coupon.lifespanTextObject.lifespan}}天</view>
							</view>
						</view>

						<u-gap height="30"></u-gap>
						<view class="f24" :class="item.useStauts  > 0?'c999':'c343'">
							{{item.coupon.range == 1?'全家政业务':'指定家政业务'}}
						</view>
					</view>
					<image src="../../static/images/me/yhq_bg.png" mode="" class="yhq_bg"
						:class="{'img-gray':item.useStauts > 0}"></image>
					<view class="yhq_staus_img">
						<image v-if="item.useStauts == 0" src="../../static/images/me/no_use.png" mode="widthFix"></image>
						<image v-if="item.useStauts == 1" src="../../static/images/me/used.png" mode="widthFix"></image>
						<image v-if="item.useStauts == 2" src="../../static/images/me/overdue.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view v-else class="no-data">
				<text>暂无数据</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCoupon
	} from '@/common/api_user.js'
	export default {
		name: '',
		data() {
			return {
				navList: [{
						name: '待使用',
						value: '0'
					},
					{
						name: '已使用',
						value: '1'
					},
					{
						name: '已失效',
						value: '2'
					}
				],
				navIndex: 0,
				listData: []
			}
		},
		onLoad(option) {
			this.getCoupon()
		},
		methods: {
			navClick(index) {
				this.navIndex = index
				this.listData = []
				this.getCoupon()
			},
			async getCoupon() {
				uni.showLoading()
				const res = await getCoupon({
					status:this.navList[this.navIndex].value
				})
				if (res.code == 200) {
					this.listData = res.data
					uni.hideLoading()
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FEF4E8;
	}

	.active {
		color: #34314F;
		font-weight: bold;
		z-index: 10;
	}

	.active::after {
		position: absolute;
		content: '';
		left: -20rpx;
		top: 0;
		height: 100%;
		width: 100rpx;
		border-radius: 30rpx;
		background-color: #FEF4E8;
		background-image: linear-gradient(to right, #FFDE6D, #FFF1A6);
		z-index: -1;
	}

	.yhq_bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 0;

	}

	.img-gray {
		filter: grayscale(100%);
		filter: gray;
		opacity: 0.7;
	}

	.yhq_staus_img {
		position: absolute;
		top: 0;
		right: 0;
		z-index: 0;
		image {
			width: 140rpx;
		}
	}
	.no-data {
		position: absolute;
		top: 40%;
		left: 50%;
		transform: translate(-50%, -50%);
		margin: 0;
	}
</style>